package charset

import "code.google.com/p/go.net/html/charset"

charset包提供了HTML文档的常见文本编码解析。

从编码标志到编码的映射参见http://encoding.spec.whatwg.org

Index

func DetermineEncoding

func DetermineEncoding(content []byte, contentType string) (e encoding.Encoding, name string, certain bool)

DetermineEncoding通过文档内容最多前1024字节数据和HTTP回复的Content-Type头,确定HTML文档的编码。

参见http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#determining-the-character-encoding

func Lookup

func Lookup(label string) (e encoding.Encoding, name string)

Lookup返回编码标志对应的编解码器和该编解码器的标准编码标志。如果label不是HTML的标准编码之一,会返回(nil, "")。r匹配时大小写敏感的,会忽略label前后端的空白。

func NewReader

func NewReader(r io.Reader, contentType string) (io.Reader, error)

NewReader返回一个将r中内容解码为UTF-8文本的io.Reader接口。本函数会调用DetermineEncoding来确定r使用的编码格式以选择对应解码器。